﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;
using IOTestMain.Classes;
using System.Net;

namespace IOTestMain
{
    class Program
    {
        // By default, the lock recursion policy for a new  
        // ReaderWriterLockSlim does not allow recursion. 
        static ReaderWriterLockSlim rwls = new ReaderWriterLockSlim();

        static void ThreadProc()
        {
            Console.WriteLine("Acquire the reader lock.");
            rwls.EnterWriteLock();

            try
            {
                Console.WriteLine("\nAttempt to acquire the reader lock recursively:");
                rwls.EnterReadLock();
            }
            catch (LockRecursionException lre)
            {
                Console.WriteLine("{0}: {1}",
                    lre.GetType().Name, lre.Message);
            }

            try
            {
                Console.WriteLine("\nAttempt to acquire the writer lock recursively:");
                rwls.EnterWriteLock();
            }
            catch (LockRecursionException lre)
            {
                Console.WriteLine("{0}: {1}",
                    lre.GetType().Name, lre.Message);
            }
            finally
            {
                if (rwls.IsWriteLockHeld)
                    rwls.ExitWriteLock();
            }

        }

        static void ReadWriteLockTest()
        {
            Thread t = new Thread(ThreadProc);
            t.Start();
            t.Join();
        }

        static void ObjectSerialize()
        {
            protocol p = new protocol(1, "tcp/ip");
            Port port = new Port("port", p);

            Port port2 = ObjectCopier.Clone<Port>(port);

            if (port2.ObjectName == port.ObjectName)
            {

            }

            if (port2.p.number == port.p.number)
            {

            }

            if (port2.p.protocolName == port.p.protocolName)
            {

            }
        }

        static void TestAttributeUsage()
        {
            BaseClass b = new BaseClass();
            DerivedClass d = new DerivedClass();

            // Display custom attributes for each class.
            Console.WriteLine("Attributes on Base Class:");
            object[] attrs = b.GetType().GetCustomAttributes(true);
            foreach (Attribute attr in attrs)
            {
                Console.WriteLine(attr);
            }

            Console.WriteLine("Attributes on Derived Class:");
            attrs = d.GetType().GetCustomAttributes(true);
            foreach (Attribute attr in attrs)
            {
                Console.WriteLine(attr);
            }
        }

        private static void objectProperty_ResetToDefault(object sender, EventArgs e)
        {

        }
        static void EventHandler()
        {
            EventHandler abc = new EventHandler(objectProperty_ResetToDefault);
            abc += objectProperty_ResetToDefault;
            abc -= objectProperty_ResetToDefault;
        }
        
        static void Main(string[] args)
        {
            GetPropertiesTest.main();
        }
    }
}
